<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,height=device-height,viewport-fit=cover,initial-scale=1,maximum-scale=5,minimal-ui">
	<title>Sensors Analytics Test</title>
	<style>
		a, button {
			margin: 0.5em;
		}
	</style>
	<script>
		(function(para) {
			var p = para.sdk_url, n = para.name, w = window, d = document, s = 'script',x = null,y = null;
			w['sensorsDataAnalytic201505'] = n;
			w[n] = w[n] || function(a) {return function() {(w[n]._q = w[n]._q || []).push([a, arguments]);}};
			var ifs = ['track','quick','register','registerPage','registerOnce','clearAllRegister','trackSignup', 'trackAbtest', 'setProfile','setOnceProfile','appendProfile', 'incrementProfile', 'deleteProfile', 'unsetProfile', 'identify','login','logout','trackLink','clearAllRegister'];
			for (var i = 0; i < ifs.length; i++) {
				w[n][ifs[i]] = w[n].call(null, ifs[i]);
			}
			if (!w[n]._t) {
				x = d.createElement(s), y = d.getElementsByTagName(s)[0];
				x.async = 1;
				x.src = p;
				y.parentNode.insertBefore(x, y);
				w[n].para = para;
			}
		})({
			sdk_url: '//m.ppdaicdn.com/act/huan/js/sensorsdata.min.js?v=1',
			name: 'sa',
			server_url: '//sensorsdata.ppdai.com/sa/?project=default',
			use_app_track: true
		});
		sa.quick('autoTrack');
	</script>
	<script>
		var alertAppBridge = function () {
			/*try {
				alert(AppBridge);
			} catch(ex) {
				alert('No AppBridge');
			}*/
		};
	</script>
	<script id="script">
		document.onreadystatechange = function () {
			/*alert('document.readyState: ' + document.readyState);
			alertAppBridge();*/
		};
		window.onload = function () {
			/*alert('window.onload');
			alertAppBridge();*/
		};
	</script>
</head>
<body style="min-height: 1200px;">
	<div>v0.0.14</div>
	<script>
		var script = document.createElement("script");
		script.setAttribute('src', 'https://m.ppdaicdn.com/act/huan/js/jquery.min.js');
		script.addEventListener('load', function () {
			/*alert('script loaded');
			alertAppBridge();*/
		});
		document.body.appendChild(script);
		setTimeout(function () {
			alert('setTimeout test');
		}, 1500);
	</script>
	<button onclick="test()">神策测试</button>
	<script>
		var test = function () {
			sa.track('h5_clk', {
				'tgt_event_id': 'h5_test',
				'tgt_name': 'h5-测试',
				'tgt_type': 'button',
				'position': '0'
			});
		};
	</script>
	<button onclick="clicktest()">点击测试</button>
	<script>
		var clicktest = function () {
			/*alert('clicked');*/
		};
	</script>
	<button onclick="showLoading()">Loading显示</button>
	<script>
		var deferDismiss = function () {
			AppBridge.dismissLoading();
		};
		var showLoading = function () {
			try {
				setTimeout(deferDismiss, 2000);
				AppBridge.showLoading();
			} catch(ex) {
				alert(ex);
				throw ex;
			}
		};
	</script>
	<button onclick="dismissLoading()">Loading隐藏</button>
	<script>
		var dismissLoading = function () {
			try {
				AppBridge.dismissLoading();
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<a href="https://m.ppdai.com/?hh#1">国庆活动跳转测试</a>
	<span>shareData测试</span>
	<script>
		window.onload = function () {
			try {
				AppBridge.shareData(JSON.stringify({
					'logoUrl': '//hh.ppdaicdn.com/static/images/home/logo.jpg',
					'title': 'title',
					'subTitle': 'subTitle',
					'shareUrl': '//m.huankachaoren.com?shared=1',
					'redbag': 1
				}));
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<a href="https://www.baidu.com" id="inApp">APP判断测试</a>
	<script>
		var $inApp = document.querySelector('#inApp');
		try {
			$inApp.setAttribute('href', AppBridge ? 'https://www.sina.com' : 'https://www.baidu.com');
		} catch(ex) {
			throw ex;
		}
	</script>
	<button onclick="navigateH5Url()">新打开页面测试</button>
	<script>
		var navigateH5Url = function () {
			try {
				AppBridge.navigateH5Url('https://m.ppdai.com', '跳转到页面');
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<button onclick="callupMap()">地图跳转测试</button>
	<script>
		var geoJSON = {
			"name": "中国石化会立加油站(江口壑桥)",
			"shopId": 137845,
			"distance": 0,
			"unit": "m",
			"tel": null,
			"address": null,
			"latitude": 37.936821,
			"longitude": 112.11271,
			"cityId": 544,
			"cityName": "太原"
		};
		var callupMap = function () {
			try {
				AppBridge.callupMap(JSON.stringify(geoJSON));
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<a href="https://www.baidu.com" id="openApp">外部打开APP</a>
	<script type="text/javascript">
		document.getElementById('openApp').onclick = function (e) {
			var ifr = document.createElement('iframe');
			ifr.src = 'huanapp://';
			ifr.style.display = 'none';
			document.body.appendChild(ifr);
			window.setTimeout(function () {
				document.body.removeChild(ifr);
			}, 3000);
		};
	</script>
	<button onclick="getUserInformation()">判断登录状态</button>
	<script>
		var getUserInformation = function () {
			try {
				var res = AppBridge.getUserInformation();
				alert('直接拿到了: ' + res);
			} catch(ex) {
				throw ex;
			}
		};
		/*try {
			AppBridge.getUserInformation('getUserInformationCallback');
		} catch(ex) {
			throw ex;
		}*/
	</script>
	<button onclick="goLogin()">跳转登录页面</button>
	<script>
		var goLogin = function () {
			try {
				AppBridge.goLogin('https://m.ppdai.com/act/huan/sensors_test_next.html', '成功回到页面');
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<button onclick="makeCall()">打电话</button>
	<script>
		var makeCall = function () {
			try {
				AppBridge.openURL('telprompt://10086');
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<button onclick="goLoan()">去发标</button>
	<script>
		var goLoan = function () {
			try {
				AppBridge.goLoan();
			} catch(ex) {
				throw ex;
			}
		};
	</script>
	<button onclick="goRequestData()">调用接口</button>
	<script>
		var goRequestData = function () {
			try {
				AppBridge.goRequestData('/BorrowApp/UserService/NewUserSetup', {}, 'goRequestDataCallback');
			} catch(ex) {
				throw ex;
			}
		};
		var goRequestDataCallback = function (data) {
			alert(data);
		};
	</script>
	<script>
		var getCookie = function (key) {
			if (key == null) {
				return document.cookie ? document.cookie.split('; ').map(item => ({
					[item.split('=')[0]]: item.split('=')[1]
				})) : null;
			}
			let resultArr = new RegExp(`(?:^| )${key}=([^;]*)(?:; |$)`, 'i').exec(document.cookie);
			return resultArr ? decodeURIComponent(resultArr[1]) : null;
		};
		if (getCookie('token')) {
			alert(getCookie('token'));
		} else {
			alert(document.cookie);
		}
	</script>
	<hr>
	<a href="sensors_test_next.html">sensors_test_next</a>
	<ul id="ul">
		<li>
			<img src="https://www.baidu.com/img/bd_logo1.png" alt="image" onload="<!-- alert('image loaded') -->">
		</li>
	</ul>
	<script>
		/*alert('page dom loaded');
		alertAppBridge();*/
	</script>
</body>
</html>
